package com.example.net

import com.tencent.mmkv.MMKV
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit

private val client by lazy {
	OkHttpClient.Builder()
		.addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
		.addInterceptor {
			val token = MMKV.defaultMMKV().decodeString("token","")
			val request = it.request().newBuilder().addHeader("token", token!!).build()
			it.proceed(request)
		}
		.build()
}
val retrofit by lazy {
	Retrofit.Builder()
		.client(client)
		.baseUrl("http://10.161.9.80:7015/")
		.addConverterFactory(GsonConverterFactory.create())
		.build()
}
inline fun <reified T>service():T = retrofit.create(T::class.java)
